'''
@Descripttion: 
@version: 
@encoding: utf-8
@Author: qiurongcan
Date: 2025-08-31 17:15:44
LastEditTime: 2025-08-31 17:19:17
'''



class Solution:
    def generateParenthesis(self, n):

        if n <= 0 :
            return []
        
        res = []
        def dfs(paths, left, right):

            if left > n or right > left:
                return

            if len(paths) == n * 2:
                res.append(paths)
                return
            dfs(paths + "(", left + 1, right)
            dfs(paths + ")", left, right + 1)

        
        dfs("", 0, 0)
        return res


